var config = require("../../../../view/config.js");
var api = require("../../../js/service.js");
avalon.component('ms-header',{
	template:require('./header.html'),
	defaults:{
		logo:'',
		config:"",
		// logon:false,
		setting:{},
		userInfo:{},
		nav:[{
			href:'/',
			name:"首页",
			path:"home"
		},{
			href:'notices.html',
			name:"通知公告",
			path:"notices"
		},{
			href:'events.html',
			name:'评审活动',
			path:'events'
		},{
			href:'reviews.html',
			name:"活动回顾",
			path:"reviews"
		}],
		getSetting:function(){
			var that = this;
			return api.getItems({
				method:api.getSysSetting,
				query:{}
			},function(res){
				// avalon.log(this)
				if(res.success){
					// console.log(res)
					// for(var attr in res.data){
					// 	if(attr){
					// 		that.setting[that] = res.data[attr]
					// 	}else{
					// 		that.setting[that] = ''
					// 	}
					// }
					that.setting = res.data
					that.fireSomething()
				}
			})
		},
		fireSomething:function(){
			var that = this
			var setNameActionCreator = function(name){
				return {
					type:'SET_NAME',
					name:name,
					setting:that.setting
				}
			}
			window.duxStore.dispatch(setNameActionCreator('setting'))
		},
		showUserMenu:function(){
			$('.user-menu').toggle()
			return false
		},
		logout:function(){
			api.clearUserInfo()
			this.userInfo = ''
		},
		onInit:function(){
			var that = this
			this.userInfo = api.getUserInfo()?JSON.parse(api.getUserInfo()):''
			// avalon.log(api.getUserInfo())
			this.logo = config.$images.DefaultLogo
			// this.getSetting();
		},
		onReady:function(e){
			var that = this
			// this.fireSomething();
			var setNameActionCreator = function(name){
				return {
					type:'SET_NAME',
					name:name,
					setting:that.setting
				}
			}
			window.duxStore.dispatch(setNameActionCreator('init'))
			this.getSetting();
		}
	}
})
